package presenter;


import java.util.Observer;

import bean.OrderBeans;
import interfaces.IOrderface;
import responsitory.OrderResponsitory;
import util.volley.ICompleteListener;
import util.volley.ResultEntity;

/**
 * Created by itboye on 2016/12/9.
 */

public class OrderPresenter extends BasePresenter implements IOrderface<OrderBeans>{
    public static final String Order_success = UserPresenter.class.getName()
            + "_Order_success";
    public static final String Order_fail = UserPresenter.class.getName()
            + "_Order_fail";

    public static final String addAll_success = BasePresenter.class.getName()
            + "_addAll_success";
    public static final String addAll_fail = BasePresenter.class.getName()
            + "_addAll_fail";
    //购物车删除
    public static final String delete_success = BasePresenter.class.getName()
            + "_delete_success";
    public static final String delete_fail = BasePresenter.class.getName()
            + "_delete_fail";
    //购物车更新
    public static final String update_success = BasePresenter.class.getName()
            + "_update_success";
    public static final String update_fail = BasePresenter.class.getName()
            + "_update_fail";
    //确认收货
    public static final String querenshouhuo_success = BasePresenter.class.getName()
            + "_querenshouhuo_success";
    public static final String querenshouhuo_fail = BasePresenter.class.getName()
            + "_querenshouhuo_fail";
    //取消订单
    public static final String quxiao_success = BasePresenter.class.getName()
            + "_quxiao_success";
    public static final String quxiao_fail = BasePresenter.class.getName()
            + "_quxiao_fail";
    public OrderPresenter(Observer observer) {
        super(observer);
    }

    /***
     * 代付款
     * @param uid
     * @param query_status
     * @param page_index
     * @param page_size
     */
    @Override
    public void onOrderPayments(String uid, String query_status, String page_index, String page_size) {
        IOrderface<OrderBeans> user = new OrderResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(Order_success);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(Order_fail);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);

                    }
                });
        user.onOrderPayments(uid, query_status,page_index,page_size);
    }

    /**
     * 购物车
     * @param uid
     */
    @Override
    public void gouWuChe(String uid) {
        IOrderface<OrderBeans> user = new OrderResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(addAll_success);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(addAll_fail);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);

                    }
                });
        user.gouWuChe(uid);
    }

    @Override
    public void gouWuCheShanChu(String uid, String id) {
        IOrderface<OrderBeans> user = new OrderResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(delete_success);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(delete_fail);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);

                    }
                });
        user.gouWuCheShanChu(uid,id);
    }

    @Override
    public void updateGouWuChe(String uid, String id, String count) {
        IOrderface<OrderBeans> user = new OrderResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(update_success);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(update_fail);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);

                    }
                });
        user.updateGouWuChe(uid,id,count);
    }

    @Override
    public void querenShouHuo(String sid, String uid, String orderCode) {
        IOrderface<OrderBeans> user = new OrderResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(querenshouhuo_success);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(querenshouhuo_fail);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);

                    }
                });
        user.querenShouHuo(sid,uid,orderCode);
    }
    @Override
    public void quxiaoDingDan(String uid, String order_code) {
        IOrderface<OrderBeans> user = new OrderResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(quxiao_success);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(quxiao_fail);
                        OrderPresenter.this.setChanged();
                        OrderPresenter.this.notifyObservers(result);

                    }
                });
        user.quxiaoDingDan(uid,order_code);
    }
}
